package cn.zspt.vank.service.impl;


import cn.zspt.vank.domain.Dish;
import cn.zspt.vank.domain.User;
import cn.zspt.vank.domain.dto.DishSale;
import cn.zspt.vank.mapper.AdminMapper;
import cn.zspt.vank.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Map<String, Object> getStatics() {
        Double yearIncome=adminMapper.getYearIncome();
        Double monthIncome=adminMapper.getMonthIncome();
        Double dayIncome=adminMapper.getDayIncome();
        Double dayIncomeAll=adminMapper.getDayIncomeAll();
        Map<String, Object> statics= new HashMap<>();
        statics.put("yearIncome",yearIncome!=null?yearIncome:0);
        statics.put("monthIncome",monthIncome!=null?monthIncome:0);
        statics.put("dayIncome",dayIncome!=null?dayIncome:0);
        statics.put("dayIncomeAll",dayIncomeAll!=null?dayIncomeAll:0);
        return statics;
    }

    @Override
    public List<DishSale> getDishSaleSort(String sortType) {
        return adminMapper.getDishSaleSort(sortType);
    }

    @Override
    public List<User> findAllUser(){
        return adminMapper.findAllUser();
    }

    @Override
    public void switchUserState(Integer userId) {
        adminMapper.switchUserState(userId);
    }

    @Override
    public void saveUser(User user) {
        adminMapper.saveUser(user);
    }

    @Override
    public List<Dish> findAllDish() {
        return adminMapper.findAllDish();
    }

    @Override
    public void updateDish(Dish dish) {
        adminMapper.updateDish(dish);
    }

    @Override
    public void saveDish(Dish dish) {
        adminMapper.saveDish(dish);
    }
}
